﻿#region << 文件说明 >>

/*----------------------------------------------------------------
 * 命名空间：Vampirewal.BlogCore.Controls
 * 唯一标识：78d04616-0052-4207-943f-041090cdb502
 * 文件名：IControl
 *
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2024/6/14 17:33:13
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/

#endregion << 文件说明 >>

namespace Vampirewal.BlogCore;

/// <summary>
/// 控件基类
/// </summary>
public abstract class ControlBase
{
    /// <summary>
    /// 控件ID
    /// <para>标记在控件的ID上</para>
    /// </summary>
    public abstract string Id { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    [Required]
    public abstract string Title { get; set; }

    /// <summary>
    /// 将控件配置的内容转成html代码
    /// </summary>
    /// <returns>html代码</returns>
    public virtual string ConverToHtml()
    {
        return ControlBuilder.ToString();
    }


    protected StringBuilder ControlBuilder { get; set; } = new StringBuilder();  
}

/// <summary>
/// 容器控件基类
/// </summary>
public abstract class ContainerControlBase : ControlBase
{
    /// <summary>
    /// 控件集合
    /// </summary>
    public abstract List<ControlBase> Children { get; internal set; }
}

/// <summary>
/// 只有1个子控件的容器控件基类
/// </summary>
public abstract class ContainerControlBaseSingle : ControlBase
{
    /// <summary>
    /// 子控件
    /// </summary>
    public abstract ControlBase Control { get; set; }
}

/// <summary>
/// 指定子容器类型的容器控件基类
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class ContainerControlBase<T> : ControlBase where T : ControlBase
{
    /// <summary>
    /// 控件集合
    /// </summary>
    public abstract List<T> Children { get; internal set; }
}